/*
 * ========================================================
 * Copyright(c) 2014 杭州龙骞科技-版权所有
 * ========================================================
 * 本软件由杭州龙骞科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * http://www.hzdracom.com/
 * ========================================================
 */
package com.shwread.android.ui.page;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.shwread.android.qysw.activity.ECommerceActivity;
import com.shwread.android.qysw.activity.MainActivity;
import com.shwread.android.qysw.activity.SuperviseActivity;
import com.shwread.android.qysw10000213.R;
import com.shwread.android.ui.widget.refresh.PullToRefreshScrollView;
import com.tgx.tina.android.ipc.framework.IUIPage;
import com.zxing.qr_codescan.MipcaActivityCapture;

import base.tina.core.task.infc.ITaskResult;
import logic.constants.DefaultConsts;


/**
 * 首页-我的
 *
 * @author 刘宾
 * @date 2015年11月26日 下午2:10:56
 */
public class TestEnterprisePage
        extends
        AbstractUIPage<MainActivity> implements View.OnClickListener {
    private static TestEnterprisePage instance;

    public static TestEnterprisePage getInstance(MainActivity t) {
        if (null == instance) {
            instance = new TestEnterprisePage(t);
        } else {
            instance.setActivity(t);
        }
        return instance;
    }

    public TestEnterprisePage(MainActivity t) {
        super(t);
    }

    private TextView tvTitle;
    private TextView T1;
    private TextView T3;
    private TextView T2;
    private ImageView ivPersion;
    private PullToRefreshScrollView refreshView;


    @Override
    public <E extends Activity> View createView(E arg0, int arg1) {
        if (null != curMyView) return curMyView;
        curMyView = bActivity.getLayoutInflater().inflate(R.layout.test, null);
        initData();
        initView();
        return curMyView;
    }

    void initData() {
    }

    void initView() {
        tvTitle = (TextView) curMyView.findViewById(R.id.common_header_name);
        ivPersion = (ImageView) curMyView.findViewById(R.id.common_header_persion);
        ivPersion.setVisibility(View.VISIBLE);
        T1 = (TextView) curMyView.findViewById(R.id.T1);
        T2 = (TextView) curMyView.findViewById(R.id.T2);
        T3 = (TextView) curMyView.findViewById(R.id.T3);
        refreshView = (PullToRefreshScrollView) curMyView.findViewById(R.id.refreshView);
        tvTitle.setText("消防专区");

        ivPersion.setOnClickListener(this);
        T1.setOnClickListener(this);
        T2.setOnClickListener(this);
        T3.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.common_header_persion:
                bActivity.goPersonalActivity();
                break;
            case R.id.T1:
                Intent intent = new Intent(bActivity, SuperviseActivity.class);
                bActivity.startActivity(intent);
                break;
            case R.id.T2:
                Intent intent1 = new Intent(bActivity, ECommerceActivity.class);
                bActivity.startActivity(intent1);
                break;
            case R.id.T3:
                    if (ContextCompat.checkSelfPermission(bActivity, Manifest.permission.CAMERA)
            != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(bActivity, new String[]{Manifest.permission.CAMERA},
                1);
    }
                Intent intent2 = new Intent(context, MipcaActivityCapture.class);
                bActivity.startActivity(intent2);
                break;
        }
    }
//    if (ContextCompat.checkSelfPermission(bActivity, Manifest.permission.CAMERA)
//            != PackageManager.PERMISSION_GRANTED) {
//        ActivityCompat.requestPermissions(bActivity, new String[]{Manifest.permission.CAMERA},
//                1);
//    }


    @Override
    public int enter(IUIPage<?> arg0) {
        return 0;
    }

    @Override
    public int leave(IUIPage<?> arg0) {
        return 0;
    }

    @Override
    public void notifyView(int arg0, Bundle arg1) {
        switch (arg0) {
            case DefaultConsts.UPDATEUI_SPLASH_DELAY_MILLIS:
                break;
        }

    }

    private Handler myHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            int msgId = msg.what;
            switch (msgId) {
                case 1:
                    break;
                default:
                    break;
            }
        }
    };

    @Override
    public void setStatus(int arg0) {

    }

    @Override
    public View updateView(int arg0, ITaskResult arg1) {
        // TODO Auto-generated method stub
        return null;
    }

    public static void destroy() {
        if (instance != null) {
            instance.dispose();
            instance = null;
        }
    }
}
